home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / EXTEND.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  3KB  |  124 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 510 of 527
  3. From : Mark Lewis                          1:3634/12.0          17 May 93  02:25
  4. To   : BRIAN PAPE
  5. Subj : File overflow
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  > HB>Your cup runnith over?...  Not quite sure what you mean by file
  8.  > HB>overflow, but it sounds like you need to increase the FILES=
  9.  > HB>in your config.sys.
  10.  
  11.  > The problem is that without allocating a new FCB for DOS, you
  12.  > can't have more than 15 or so files open at a time in TP, no
  13.  > matter WHAT the CONFIG.SYS FILES= statement says.  (By default,
  14.  
  15. i cannot remember exactly what INT $21 function $6700 is but here's a PD unit i
  16. got from borland's bbs the other day... i've trimmed the text down for
  17. posting... if anyone really needs everything that comes with it, they should
  18. look for EXTEND6.*}
  19.  
  20.  
  21. unit Extend;
  22. {This extends the number of FILE handles from 20 to 255}
  23. {DOS requires 5 for itself. Applications can use up to 250}
  24.  
  25. interface
  26.  
  27. implementation
  28. uses dos;
  29. const
  30.   Handles =255;
  31.   {You can reduce the value passed to Handles if fewer files}
  32.   {are required.}
  33.  
  34. var
  35.   reg:registers;
  36.   begin
  37.   {Check the Dos Version}
  38.   {This technique only works for DOS 3.0 or later}
  39.   reg.ah:=$30;
  40.   MsDos(reg);
  41.   if reg.al<3 then
  42.   begin
  43.     writeln('Extend Unit Require DOS 3.0 or greater');
  44.     halt(1);
  45.   end;
  46.  
  47.   {Reset the FreePtr}
  48.   {This reduces the heap space used by Turbo Pascal}
  49.   if HeapOrg<>HeapPtr then
  50.   {Checks to see if the Heap is empty}
  51.   begin
  52.     write('Heap must be empty before Extend unit initializes');
  53.     writeln;
  54.     halt(1);
  55.   end;
  56.   HeapEnd:=ptr(Seg(HeapEnd^)-(Handles div 8 +1), Ofs(HeapEnd^));
  57.  
  58.   {Determine how much memory is allocated to program}
  59.   {Reg.Bx will return how many paragraphs used by program}
  60.   reg.ah:=$4A;
  61.   reg.es:=PrefixSeg;
  62.   reg.bx:=$FFFF;
  63.   msdos(reg);
  64.  
  65.   {Set the program size to the allow for new handles}
  66.   reg.ah:=$4A;
  67.   reg.es:=PrefixSeg;
  68.   reg.bx:=reg.bx-(Handles div 8 +1);
  69.   msdos(reg);
  70.  
  71.   {Error when a Block Size is not appropriate}
  72.   if (reg.flags and 1)=1 then
  73.   begin
  74.     Writeln('Runtime Error ',reg.ax,' in Extend.');
  75.     halt(1);
  76.   end;
  77.  
  78.   {Allocate Space for Additional Handles}
  79.   reg.ah:=$67;
  80.   reg.bx:=Handles;
  81.   MsDos(reg);
  82. end.
  83.  
  84. Write the following program  to  a  separate  FILE.  This program
  85. tests the  EXTEND  unit.    This  test  should be done on systems
  86. equipped with a hard disk.
  87.  
  88. program TestEx;
  89.  
  90. uses EXTEND;
  91. type
  92.   filearray=array[1..250] of text;
  93. var
  94.   f:^filearray;
  95.   i:integer;
  96.   s:string;
  97.  
  98. begin
  99.   {Allocate Space for fILE Variable Table}
  100.   new(f);
  101.   {oPEN 250 files simultaneously}
  102.   for i:=1 to 250 do
  103.   begin
  104.     str(i,s);
  105.     Assign(f^[i],'Dum'+s+'.txt');
  106.     rewrite(f^[i]);
  107.     writeln('Open #',s);
  108.   end;
  109.   {Write some text to the files}
  110.   for i:=1 to 250 do
  111.   write(f^[i],'This is a test file');
  112.   {Close the files}
  113.   for i:=1 to 250 do
  114.   begin
  115.     close(f^[i]);
  116.     writeln('Closing #',i);
  117.   end;
  118.   {Erase the files}
  119.   for i:=1 to 250 do
  120.   begin
  121.     erase(f^[i]);
  122.     writeln('Erasing #',i);
  123.   end;
  124. end.